home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
ca29_3.zip
/
XLATE.CMD
< prev
Wrap
OS/2 REXX Batch file
|
1990-06-21
|
15KB
|
638 lines
; ----- COM-AND Edit transation tables
;
; This script opens a window and allows the editing of translation
; tables. COM-AND supports two transations: incoming and outgoing.
; The first 128 bytes of the incoming table are displayed on entry.
;
; The incoming table is 256 entries. The outgoing table is the same
; size. The 'n'th position represents the translation value for the
; character with value 'n'.
;
; Translation may be enabled here in this script - and in COM-AND's
; Alt-V emulations.
;
; R.McG, commenced 1/89
; ----- Usages -----------------
; S19 -----> COM-AND.XLT file name to be used
; S10-S17 -> The file loaded into memory
; N99 -----> Display page (0,1,2,3)
; FLAG(9) -> Hex/decimal switch
; FLAG(8) -> Modification to file
; ------------------------------
; Initialization
;
;* TRACE ON
ON ESCAPE GOSUB Exit ; SAVE is performed in Window
LEGEND " Edit translations"
SET TTHRU OFF ; Disallow typeahead
N99 = 0 ; Base of current window
SET FLAG(9) OFF ; Hex/decimal flag (true = hex)
SET FLAG(8) OFF ; Modification flag
;
; Initialize, and paint an initial window
;
GOSUB Set_Fname ; S19 -> target file
UPPER S19 ; .. make nice
GOSUB Load ; Load values
GOSUB Window ; Open the window
;
; Main-loop - look for keyentry
;
Main_Loop:
ATSAY 22,11 (default) " "
LOCATE 22,11
KEYGET S0 ; Get a keystroke
;
; Act upon the keystroke
;
SWITCH S0
CASE "4900" ; Pgup
GOTO PgUp
ENDCASE
CASE "5100" ; PgDn
GOTO PgDn
ENDCASE
CASE "4700" ; Home
GOTO Home
ENDCASE
CASE "4F00" ; End
GOTO End
ENDCASE
CASE "H" ; H)ex
SET FLAG(9) ON
GOSUB DISPPAGE
GOTO Main_Loop
ENDCASE
CASE "D" ; D)ecimal
SET FLAG(9) OFF
GOSUB DISPPAGE
GOTO Main_Loop
ENDCASE
CASE "S" ; S)ave
GOSUB Store
GOTO Main_Loop
ENDCASE
CASE "N" ; S)ave
IF FLAG(8)
GOSUB Store ; Save on disk
SET FLAG(8) OFF
ENDIF
SET TRAN ON
GOTO Main_Loop
ENDCASE
CASE "F" ; S)ave
SET TRAN OFF
GOTO Main_Loop
ENDCASE
ENDSWITCH
;
; Begin numeric entry
;
IF NOT NULL S0(1:3) ; Disallow other special keys
SOUND 100,100
GOTO Main_Loop
ENDIF
GOSUB Enter ; Enter #
GOTO Main_Loop ; And continue
;
; ----- Page up (cycle backwards through possible values)
;
PgUp:
DEC N99
IF LT N99 0
N99 = 3
ENDIF
GOSUB DispPage
GOTO Main_Loop
;
; ----- Page down (cycle forwards through possible values)
;
PgDn:
INC N99
IF GT N99 3
N99 = 0
ENDIF
GOSUB DispPage
GOTO Main_Loop
;
; ----- Home (move to first line)
;
Home:
N99 = 0
GOSUB DispPage
GOTO Main_Loop
;
; ----- End (Move to last line)
;
End:
N99 = 3
GOSUB DispPage
GOTO Main_Loop
;
; ----- Subroutine Exit - terminate the process
;
Exit:
IF FLAG(8) ; If table modified
GOSUB Ask_Save ; Ask if to save
ENDIF
DO ; CLose any open windows
WCLOSE
UNTIL FAILURE
EXIT
;
; ----- Subroutine: Enter a value
; .. on entry S0 -> The first keystroke
; .. S9 within this subroutine the field being constructed
; .. N6 within this subroutine is an index to field being constructed
;
Enter:
N6 = 0 ; Index to field being built
S9 = "" ; Clear field
UPPER S0 ; Make upper case
CTOI S0 N0 ; Easier comparison
IF NOT ((GE N0 48 and LE N0 57) or EQ N0 88) ; Allow 0-9 and 'x'
SOUND 100,100
RETURN
ENDIF
CURSOR N0,N1
INC N1
LOCATE N0,N1
GOTO Keyin
;
; Accept another keypress
;
Keypress:
KEYGET S0 ; Get more from keybd
;
; Catch backspace (and equivalent cursor left) here
;
Keyin:
IF STRCMP S0 "08" or STRCMP S0 "4B00"; Backspace or cursor left
IF GT N6 0
CURSOR N0,N1
ATSAY N0,N1 (default) "^H"
DEC N6
ENDIF
IF EQ N6 0
RETURN ; Nop at this pt
ENDIF
GOTO Keypress
ENDIF
;
; Catch carriage return (and equivalent space/tab) here
;
IF STRCMP S0 "0D" or STRCMP S0 " " or STRCMP S0 "09" ; cr, space, tab
IF EQ N6 0 ; Look for nothing done
RETURN ; Empty field
ENDIF
GOTO End_Entry ; Done - try to convert it
ENDIF
;
; Other control keys abort entry
;
IF NOT NULL S0(1:3) ; If a special key
GOTO Abort_Entry ; Exit on special key
ENDIF
;
; Filter only 0-9, a-f, and 'x' here
;
UPPER S0 ; Make upper case
CTOI S0 N0 ; Easier comparison
IF NOT ((GE N0 48 and LE N0 57) or (GE N0 65 and LE N0 70) or EQ N0 88)
SOUND 100,100
GOTO Keypress
ENDIF
;
; Add the character to the string being constructed
;
CURSOR N0,N1
ATSAY N0,N1 (default) S0
INC N1
LOCATE N0,N1
S9(N6:N6) = S0 ; Add the key
INC N6 ; Add to index
GOTO Keypress ; And continue
;
; Abort entry and return to main
;
Abort_Entry:
RETURN
;
; Error in entry
;
Entry_Error:
SOUND 400,100
RETURN
;
; End of entry - catch empty field
;
End_Entry:
IF EQ N6 0 ; EMpty field
RETURN
ENDIF
;
; Convert a leading 'x' into '0x'
;
IF STRCMP S9(0:0) "X" ; 'x' in col 0
S9 = "0"&S9 ; Add an initial 0
ENDIF
;
; Try to convert the char
;
ATOI S9 N0 ; Convert
IF ERROR or (LT N0 0 or GT N0 255)
GOTO Entry_Error ; .. indicate error
ENDIF
;
; Lookup the value obtained
;
GOSUB Get_Value ; Using N0, get its translation into N1
S0 = "Char %03d (x%02x) currently translates to %03d (x%02x)"
STRFMT S1 S0 N0,N0 N1,N1 ; Construct prompt
;
; Open a window for the entry of the translation
;
WOPEN 19,0, 22,78 (default) TenterXIT
ATSAY 20,2, (default) S1 ; D
ATSAY 21,2 (default) "New translation: "
ATSAY 22,28 (default) " Press ESC to cancel "
;
; Ask for the translation
;
Tenter:
ATGET 21,19 (default) 4 S0 ; Get new translation
;
; Catch empty response (Tenter_ESC also clears S0)
;
IF NULL S0 ; EMpty field
WCLOSE ; Drop window
RETURN
ENDIF
;
; Convert a leading 'x' into '0x'
;
IF STRCMP S0(0:0) "X" ; 'x' in col 0
S0 = "0"&S0 ; Add an initial 0
ENDIF
;
; Try to convert the char
;
ATOI S0 N1 ; Convert
IF ERROR or (LT N1 0 or GT N1 255)
SOUND 400,100
GOTO Tenter ; .. Try again
ENDIF
;
; We have a value (N0 translating into N1)
;
WCLOSE
SET FLAG(8) ON ; Mark updated
GOSUB Set_Value
;
; Redisplay the line or page modified
;
N3 = N0/128 ; N3 -> page #
IF GE N99 2 ; N99 -> incoming/outgoing
N3 = N3+2
ENDIF
IF NE N3 N99
N99 = N3 ; Set new page no
GOSUB DispPage ; Display the new page
ELSE
N98 = N0 & 15 ; Make N98 = 0-15
GOSUB DispLine ; Just redo the line (n98 = lineno)
ENDIF
RETURN
;
; ----- Escape during entry routine
;
TenterXit:
S0 = "" ; Null input field
RETURN
;
; ----- Get a translation value
; On entry N0 -> the char being translated
; On exit N1 <- the translation
;
Get_Value:
N3 = N0/64 ; Mask string # (0-3)
IF GE N99 2 ; Decide incoming/outgoing
N3 = N3+4 ; Sel within incoming/outgoing tables
ENDIF
SWITCH N3 ; Switch on string # (0-7)
CASE 0
S0 = S10
ENDCASE
CASE 1
S0 = S11
ENDCASE
CASE 2
S0 = S12
ENDCASE
CASE 3
S0 = S13
ENDCASE
CASE 4
S0 = S14
ENDCASE
CASE 5
S0 = S15
ENDCASE
CASE 6
S0 = S16
ENDCASE
CASE 7
S0 = S17
ENDCASE
ENDSWITCH
CTOI S0(N0&63) N1
RETURN
;
; ----- Store a translation value
; On entry N0 -> the